cmake_minimum_required(VERSION 3.10)
project(data_struct_code)
set(CMAKE_CXX_STANDARD 17)

include(FetchContent)

FetchContent_Declare(
        googletest
        GIT_REPOSITORY https://github.com/google/googletest.git
        GIT_TAG v1.16.0
)
# 自动查找所有包含 .h / .hpp 的子目录
file(GLOB_RECURSE HEADER_FILES RELATIVE ${CMAKE_SOURCE_DIR} src/*.h src/*.hpp)

# 提取所有头文件所在的目录
set(INCLUDE_DIRS "")
foreach (header ${HEADER_FILES})
    get_filename_component(dir ${header} DIRECTORY)
    list(APPEND INCLUDE_DIRS ${dir})
endforeach ()

# 去重（防止重复添加相同目录）
list(REMOVE_DUPLICATES INCLUDE_DIRS)

# 加入 include 路径
include_directories(${INCLUDE_DIRS})

FetchContent_MakeAvailable(googletest)

# 测试顺序表
add_executable(test_seqlist
        test/sequential_list/test_seqlist.cpp
        src/sequential_list/SeqList.cpp
)
target_link_libraries(test_seqlist PRIVATE gtest_main)

# 测试单链表
add_executable(test_singleLinkList
        test/link_list/test_single_linkList.cpp
        src/link_list/SingleLinkList.cpp
)
target_link_libraries(test_singleLinkList PRIVATE gtest_main)

# 测试双向链表
add_executable(test_doubleLinkList
        test/link_list/test_doubleLinkList.cpp
        src/link_list/DoubleLinkList.cpp
)
target_link_libraries(test_doubleLinkList PRIVATE gtest_main)

# 测试循环单链表
add_executable(test_circularLinkList
        test/link_list/test_circularLinkList.cpp
        src/link_list/CircularLinkList.cpp
)
target_link_libraries(test_circularLinkList PRIVATE gtest_main)

# 静态链表
add_executable(test_staticLinkList
        test/link_list/test_staticLinkList.cpp
        src/link_list/StaticLinkList.cpp
)
target_link_libraries(test_staticLinkList PRIVATE gtest_main)

# 栈
add_executable(test_array_stack
        test/stack/test_array_stack.cpp
        src/stack/ArrayStack.cpp
)
target_link_libraries(test_array_stack PRIVATE gtest_main)

add_executable(test_link_list_stack
        test/stack/test_link_list_stack.cpp
        src/stack/LinkedListStack.cpp
)
target_link_libraries(test_link_list_stack PRIVATE gtest_main)

# 表达式求值
add_executable(test_expr
        test/stack/test_expr.cpp
        src/stack/expr.cpp
)
target_link_libraries(test_expr PRIVATE gtest_main)

